package nancal.mp.db.mongo.entity.wx

import nancal.mp.db.mongo.UserPartnerTypeEnum
import nancal.mp.db.mongo.UserRoleEnum
import nancal.mp.db.mongo.base.shop.BaseInvoiceData
import nancal.mp.db.mongo.base.shop.ReceiveAddressDataInfo
import nancal.mp.db.mongo.base.wx.OpenIdNameUrl
import nbcp.base.db.IdName
import nbcp.base.db.annotation.DbEntityGroup
import nbcp.base.db.annotation.DbEntityIndex
import nbcp.base.db.annotation.DbEntityIndexes
import nbcp.base.model.BaseMarkEntity
import nbcp.myoql.db.comm.RemoveToSysDustbin
import nbcp.myoql.db.mongo.entity.BasicUser
import nbcp.myoql.db.mongo.entity.BasicUserLoginInfo
import nbcp.myoql.weixin.WxUserData
import org.springframework.data.mongodb.core.mapping.Document
import java.io.Serializable
import java.time.LocalDateTime


@Document
@DbEntityGroup("wx")
data class WxFormId(
        var openid: String = "",
        var formId: String = "",
        var prePayId: String = "",  //prePayId 会有三条记录
        var used: Boolean = false,
        var usedAt: LocalDateTime = LocalDateTime.now()
) : BaseMarkEntity()


@Document
@DbEntityGroup("wx")
@RemoveToSysDustbin
@DbEntityIndexes(
        DbEntityIndex("wxUserInfo.openid", unique = true),
)
open class WxAppUser(
//        var invoices: MutableList<InvoiceData> = mutableListOf(InvoiceData(default = true)),

//        var logoUrl: String = "",     //远程URL
//        var isAdmin: Boolean = false,  //是否是员工

        //新加字段   合伙人使用
        var partnerType: UserPartnerTypeEnum? = null,
        var role: MutableList<UserRoleEnum> = mutableListOf(),

        var wxUserInfo: WxUserData = WxUserData(),

        var commission: Int = 0,   //合伙人分成比例 百分比,需要设置一个默认分成比例,比例对下级生效
        var superior: OpenIdNameUrl = OpenIdNameUrl(),  // 分享绑定的上级关系 , 数据库只保存最基本的上级关系。

        var qrCodeScene: String = "", //我的二维码场景值
        var qrCodeSceneCreateAt: LocalDateTime = LocalDateTime.now(), //我的二维码场景值

        var receiveAddresses: MutableList<ReceiveAddressDataInfo> = mutableListOf(),    //收货地址

        var invoices: MutableList<BaseInvoiceData> = mutableListOf(),   // 发票抬头

        var scores: Int = 0,     //可用积分/豆

        var isLocked: Boolean = false,
        var lockedRemark: String = ""
) : BasicUser(), Serializable {

}


/**
 * C员工登录用户
 */
@Document
@DbEntityGroup("wx")
@DbEntityIndexes(
        DbEntityIndex("loginName", unique = true),
)
data class WxAppLoginUser(
        var errorLoginTimes: Byte = 0
) : BasicUserLoginInfo(), Serializable


/**
 * 站内信
 */
@Document
@DbEntityGroup("wx")
@RemoveToSysDustbin
data class AppUserInnerMessage(
        var type: String = "",
        var user: IdName = IdName(),
        var title: String = "",
        var content: String = "",
        var data: String = "",
        var read: Boolean = false,
        var readAt: LocalDateTime? = null,
        var sender: IdName = IdName(),
        var sendAt: LocalDateTime? = null
) : BaseMarkEntity()

